Skip to content

Fix Source.targetPath incorrectly aligned to basedir#12206

Merged
gnodet merged 1 commit into
apache:masterfrom
gnodet:fix/resource-targetpath-compat
Jun 4, 2026
Merged

Fix Source.targetPath incorrectly aligned to basedir#12206
gnodet merged 1 commit into
apache:masterfrom
gnodet:fix/resource-targetpath-compat

Conversation

@gnodet

@gnodet gnodet commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • DefaultModelPathTranslator.alignToBaseDirectory(Source) was incorrectly resolving Source.targetPath against the project basedir, converting relative paths like META-INF/tags/rdc into absolute paths like /path/to/project/META-INF/tags/rdc
  • This caused maven-resources-plugin to copy resources to wrong locations when using POM 4.1.0 <source> elements with <targetPath>
  • The targetPath is relative to the output directory (target/classes), not the project basedir, so it must not be aligned during model path translation

Test plan

  • Unit tests: DefaultModelPathTranslatorTest — verifies Source directory is aligned but targetPath is not, dot-prefixed targetPath stays relative, Resource directory is aligned but targetPath is not
  • Integration tests: ProjectBuilderTest#testSourceTargetPathRemainsRelative — verifies POM 4.1.0 <source> targetPath stays relative through SourceRoot API and compat layer
  • Integration tests: ProjectBuilderTest#testResourceTargetPathRemainsRelativeInCompatLayer — verifies POM 4.0.0 <resource> targetPath stays relative
  • Manual verification: POM 4.1.0 with <source><targetPath>META-INF/tags/rdc</targetPath></source> now copies to target/classes/META-INF/tags/rdc/ (was copying to /path/to/project/META-INF/tags/rdc/)
  • Existing test suites pass for impl/maven-impl and impl/maven-core

🤖 Generated with Claude Code

gnodet added a commit that referenced this pull request Jun 2, 2026
Cherry-pick from fix/resource-targetpath-compat branch.
Supersedes earlier #12178 cherry-pick with expanded fix.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet added this to the 4.0.0-rc-6 milestone Jun 2, 2026

@Bukama Bukama left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing tests

Error:  Failures: 
Error:    MavenITmng4559MultipleJvmArgsTest.testMultipleJvmArgs:56 expected: <value1> but was: <${test.prop1}>
Error:    MavenITmng4559SpacesInJvmOptsTest.testIt:52 expected: <foo bar> but was: <${prop.jvm-opts}>

@gnodet gnodet force-pushed the fix/resource-targetpath-compat branch from 29c67b5 to ba00e3c Compare June 3, 2026 09:51
@gnodet

gnodet commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

The second commit (test isolation fix) has been dropped — it referenced static fields that only existed in an older version of the codebase and was causing compilation failures on master. The PR is now a single clean commit fixing only the Source.targetPath alignment issue.

CI is fully green (19/19 checks pass).

@Bukama could you re-review? The changes-requested items should be addressed by dropping that commit entirely.

The DefaultModelPathTranslator was aligning Source.targetPath to the
project basedir, converting relative paths like "META-INF/tags/rdc"
into absolute paths. This caused maven-resources-plugin to copy
resources to wrong locations (e.g., /META-INF/tags/rdc instead of
target/classes/META-INF/tags/rdc).

The targetPath is relative to the output directory (target/classes or
target/test-classes), not the project basedir, so it must not be
resolved against basedir during model path translation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet force-pushed the fix/resource-targetpath-compat branch from ba00e3c to 08072a3 Compare June 4, 2026 07:13
@gnodet

gnodet commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

This PR has been rebased onto master and now includes consolidated test coverage from both #12206 and #12178 (which has been closed as duplicate). The failing commit from the earlier review has been dropped. @Bukama could you re-review? CI should be clean now.

@gnodet gnodet requested a review from Bukama June 4, 2026 09:12
@gnodet gnodet merged commit dac6ab1 into apache:master Jun 4, 2026
41 of 42 checks passed
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown

@gnodet Please assign appropriate label to PR according to the type of change.

gnodet added a commit that referenced this pull request Jun 4, 2026
The DefaultModelPathTranslator was aligning Source.targetPath to the
project basedir, converting relative paths like "META-INF/tags/rdc"
into absolute paths. This caused maven-resources-plugin to copy
resources to wrong locations (e.g., /META-INF/tags/rdc instead of
target/classes/META-INF/tags/rdc).

The targetPath is relative to the output directory (target/classes or
target/test-classes), not the project basedir, so it must not be
resolved against basedir during model path translation.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@gnodet gnodet added the bug Something isn't working label Jun 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants